package com.fudan.ext.entities;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.springframework.context.annotation.Lazy;

@Entity
@Table(name = "t_question")
public class Question {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer questionId;
	
	private String question;
	
	@ManyToOne(fetch= FetchType.EAGER, cascade = CascadeType.MERGE)
	private User createdOwner;
	
	@ManyToMany(fetch= FetchType.EAGER, cascade = CascadeType.MERGE)
	private Set<User> likeUser = new HashSet<User>();
	private Date createdDate = new Date();
	
	public Question() {
		super();
	}

	public Question(String question, User createdOwner) {
		this.question = question;
		this.createdOwner = createdOwner;
	}
	
	public String getQuestion() {
		return question;
	}

	public void setQuestion(String question) {
		this.question = question;
	}

	public User getCreatedOwner() {
		return createdOwner;
	}

	public void setCreatedOwner(User createdOwner) {
		this.createdOwner = createdOwner;
	}

	public Integer getQuestionId() {
		return questionId;
	}

	public void setQuestionId(Integer questionId) {
		this.questionId = questionId;
	}

	public Set<User> getLikeUser() {
		return likeUser;
	}

	public void setLikeUser(Set<User> likeUser) {
		this.likeUser = likeUser;
	}

	public Date getCreatedDate() {
		return createdDate;
	}


	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}


	@Override
	public String toString() {
		return "Question [questionId=" + questionId + ", question=" + question + ", createdOwner=" + createdOwner
				+ ", likeUser=" + likeUser + ", createdDate=" + createdDate + "]";
	}

}
